<?php

//gets URL argument
$input=$_GET['input'];

//load database user & pass
require_once('sql-info.php');

//gets connection to database
$con = mysql_connect($mysql_host,$mysql_user,$mysql_password);

if(!$con)
{
	die('Could not connect: '.mysql_error());
}

mysql_select_db($mysql_database, $con);

$query="SELECT * FROM locations WHERE name='$input' OR abbr='$input'";
$results = mysql_query($query);
$row = mysql_fetch_assoc($results);

//if a match was found
if($row)
{
	//get name, x, y
	$name = $row['name'];
	$x = $row['x'];
	$y = $row['y'];
	
	//return name and x,y coordinates
	echo('{"name":"'.$name .'", "x":"'.$x.'", "y":"'.$y.'"}');
}
//no matches found
else
{
	echo "ERROR";
}

//close sql connection
mysql_close($con);

?>
